package com.falcon.authority.controller;

import com.falcon.authority.domain.dos.MenuDO;
import com.falcon.authority.domain.po.MenuPO;
import com.falcon.authority.domain.req.MenuQuery;
import com.falcon.authority.domain.req.MenuRequest;
import com.falcon.authority.service.IMenuService;
import com.falcon.core.controller.IBaseController;
import com.falcon.core.domain.BasePager;
import com.falcon.core.domain.BaseResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/authority/menu")
@Tag(name = "MenuController", description = "菜单权限表-接口")
public class MenuController  implements IBaseController {

    @Autowired
    private IMenuService menuService;

    @Operation(summary = "新增")
    @PostMapping("/save")
    public BaseResponse<Long> save(@Valid @RequestBody MenuRequest request) {

        Long id =  this.menuService.save(request);

        return BaseResponse.success(id);
    }

    @Operation(summary = "修改")
    @PutMapping("/update/{id}")
    public BaseResponse<Boolean> update(@PathVariable Long id, @Valid @RequestBody MenuRequest request) {

        Boolean success =  this.menuService.update(id, request);

        return BaseResponse.success(success);
    }

    @Operation(summary = "删除")
    @DeleteMapping("/delete/{id}")
    public BaseResponse<Boolean> deleteById(@PathVariable Long id) {

        Boolean success =  this.menuService.deleteById(id);

        return BaseResponse.success(success);
    }

    @Operation(summary = "批量删除")
    @PostMapping("/batchDelete")
    public BaseResponse<Integer> batchDelete(@RequestBody List<Long> ids) {

        Integer num =  this.menuService.batchDelete(ids);

        return BaseResponse.success(num);
    }

    @Operation(summary = "查询基本信息")
    @GetMapping("/{id}")
    public BaseResponse<MenuPO> detail(@PathVariable Long id) {

        MenuPO MenuPO =  this.menuService.queryById(id);

        return BaseResponse.success(MenuPO);
    }


    @Operation(summary = "列表查询")
    @PostMapping("/list")
    public BaseResponse<List<MenuPO>> list(@RequestBody MenuQuery request) {

        List<MenuPO> list =  this.menuService.queryList(request);

        return BaseResponse.success(list);
    }

    @Operation(summary = "分页查询")
    @PostMapping("/pager")
    public BaseResponse<BasePager<MenuPO>> pager(@RequestBody MenuQuery request) {

        BasePager<MenuPO> pager =  this.menuService.queryPager(request);

        return BaseResponse.success(pager);
    }

    @Operation(summary = "树状")
    @PostMapping("/tree")
    public BaseResponse<List<MenuDO>> tree(@RequestBody MenuQuery request) {

        List<MenuDO> treeResult = this.menuService.queryTree(request);

        return BaseResponse.success(treeResult);
    }
}
